package com.zouma.service;

import com.zouma.pojo.HistCapitalFlow;
import jxl.Sheet;
import jxl.Workbook;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: serein
 * @DateTime: 2021/7/8 21:22
 * @Description:
 */
public class HistCapitalFlowService {

    /**
     * 查询指定目录中电子表格中所有的数据
     * @param file 文件完整路径
     * @return
     */
    public static List<HistCapitalFlow> getAllByExcel(String file){
        List<HistCapitalFlow> list=new ArrayList<HistCapitalFlow>();
        try {
            Workbook rwb=Workbook.getWorkbook(new File(file));
            Sheet rs=rwb.getSheet(0);//或者rwb.getSheet(0)
            int clos=rs.getColumns();//得到所有的列
            int rows=rs.getRows();//得到所有的行

            System.out.println(" 行： "+clos+" 列:"+rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {

                    String id=rs.getCell(j++, i).getContents();//默认最左边编号也算一列 所以这里得j++
                    String occurrenceDate=rs.getCell(j++, i).getContents();
                    String securityName=rs.getCell(j++, i).getContents();
                    String securityCode=rs.getCell(j++, i).getContents();
                    String dealVolume=rs.getCell(j++, i).getContents();
                    String capitalOccurCount=rs.getCell(j++, i).getContents();
                    String dealPrice=rs.getCell(j++, i).getContents();
                    String dealMoney=rs.getCell(j++, i).getContents();
                    String innerCapitalAccount=rs.getCell(j++, i).getContents();
                    String businessCategory=rs.getCell(j++, i).getContents();
                    String exchangeCurrency=rs.getCell(j++, i).getContents();
                    String exchangeCode=rs.getCell(j++, i).getContents();
                    String assetLiabCategory=rs.getCell(j++, i).getContents();
                    String marketCode=rs.getCell(j++, i).getContents();
                    String productCode=rs.getCell(j++, i).getContents();

                    System.out.println(id+occurrenceDate+securityName+securityCode+businessCategory);

                    list.add(new HistCapitalFlow(
                            id,occurrenceDate,securityName,securityCode,dealVolume,
                            capitalOccurCount,dealPrice,dealMoney,innerCapitalAccount,
                            businessCategory,exchangeCurrency,exchangeCode,assetLiabCategory,marketCode,productCode));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;

    }

}
